// pages/hotsongs/hotsongs.ts
Page({
  /**
   * 页面的初始数据
   */
  data: {
    detailsDate: {} as Date, // 头部热歌的日期
    details: [] as string | Record<string, any> | ArrayBuffer,
    times: <string | number>"",
  },
  month: <string | number>"",
  date: <string | number>"",

  /* 最新音乐跳转详情页 */
  toLatest(e: any) {
    // console.log("--", e.currentTarget.dataset.itemId);
    let latest = e.currentTarget.dataset.itemId;
    wx.navigateTo({
      url: "/pages/newsongDetails/newsongDetails?newId=" + latest,
    });
  },

  /** * 生命周期函数--监听页面加载*/
  onLoad() {
    wx.request({
      url: "http://localhost:3000/playlist/detail?id=3778678",
      success: (res) => {
        // console.log(res.data);
        this.setData({
          detailsDate: new Date((res.data as any).playlist.updateTime),
          details: (res.data as any).playlist.tracks.slice(0, 20),
        });
        (this.month = this.data.detailsDate.getMonth() + 1),
          (this.month = this.month < 10 ? "0" + this.month : " this.month"),
          (this.date = this.data.detailsDate.getDate()),
          (this.date = this.date < 10 ? "0" + this.date : this.date),
          this.setData({
            times: this.month + "月" + this.date + "日",
          });
      },
    });
  },
  /** * 生命周期函数--监听页面初次渲染完成*/
  onReady() {},
  /** * 生命周期函数--监听页面显示 */
  onShow() {},
  /** * 生命周期函数--监听页面隐藏 */
  onHide() {},
  /** * 生命周期函数--监听页面卸载 */
  onUnload() {},
  /** * 页面相关事件处理函数--监听用户下拉动作 */
  onPullDownRefresh() {},
  /** * 页面上拉触底事件的处理函数 */
  onReachBottom() {},
  /** * 用户点击右上角分享 */
  onShareAppMessage() {},
});
